1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module sourceview.SnippetContext; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import sourceview.c.functions; 33 public import sourceview.c.types; 34 private import std.algorithm; 35 36 37 /** 38 * Context for expanding [class@SnippetChunk]. 39 * 40 * This class is currently used primary as a hashtable. However, the longer 41 * term goal is to have it hold onto a `GjsContext` as well as other languages 42 * so that [class@SnippetChunk] can expand themselves by executing 43 * script within the context. 44 * 45 * The [class@Snippet] will build the context and then expand each of the 46 * chunks during the insertion/edit phase. 47 */ 48 public class SnippetContext : ObjectG 49 { 50 /** the main Gtk struct */ 51 protected GtkSourceSnippetContext* gtkSourceSnippetContext; 52 53 /** Get the main Gtk struct */ 54 public GtkSourceSnippetContext* getSnippetContextStruct(bool transferOwnership = false) 55 { 56 if (transferOwnership) 57 ownedRef = false; 58 return gtkSourceSnippetContext; 59 } 60 61 /** the main Gtk struct as a void* */ 62 protected override void* getStruct() 63 { 64 return cast(void*)gtkSourceSnippetContext; 65 } 66 67 /** 68 * Sets our main struct and passes it to the parent class. 69 */ 70 public this (GtkSourceSnippetContext* gtkSourceSnippetContext, bool ownedRef = false) 71 { 72 this.gtkSourceSnippetContext = gtkSourceSnippetContext; 73 super(cast(GObject*)gtkSourceSnippetContext, ownedRef); 74 } 75 76 77 /** */ 78 public static GType getType() 79 { 80 return gtk_source_snippet_context_get_type(); 81 } 82 83 /** 84 * Creates a new #GtkSourceSnippetContext. 85 * 86 * Generally, this isn't needed unless you are controlling the 87 * expansion of snippets manually. 88 * 89 * Returns: a #GtkSourceSnippetContext 90 * 91 * Throws: ConstructionException GTK+ fails to create the object. 92 */ 93 public this() 94 { 95 auto __p = gtk_source_snippet_context_new(); 96 97 if(__p is null) 98 { 99 throw new ConstructionException("null returned by new"); 100 } 101 102 this(cast(GtkSourceSnippetContext*) __p, true); 103 } 104 105 /** 106 * Removes all variables from the context. 107 */ 108 public void clearVariables() 109 { 110 gtk_source_snippet_context_clear_variables(gtkSourceSnippetContext); 111 } 112 113 /** */ 114 public string expand(string input) 115 { 116 auto retStr = gtk_source_snippet_context_expand(gtkSourceSnippetContext, Str.toStringz(input)); 117 118 scope(exit) Str.freeString(retStr); 119 return Str.toString(retStr); 120 } 121 122 /** 123 * Gets the current value for a variable named @key. 124 * 125 * Params: 126 * key = the name of the variable 127 * 128 * Returns: the value for the variable, or %NULL 129 */ 130 public string getVariable(string key) 131 { 132 return Str.toString(gtk_source_snippet_context_get_variable(gtkSourceSnippetContext, Str.toStringz(key))); 133 } 134 135 /** 136 * Sets a constatnt within the context. 137 * 138 * This is similar to a variable set with [method@SnippetContext.set_variable] 139 * but is expected to not change during use of the snippet. 140 * 141 * Examples would be the date or users name. 142 * 143 * Params: 144 * key = the constant name 145 * value = the value of the constant 146 */ 147 public void setConstant(string key, string value) 148 { 149 gtk_source_snippet_context_set_constant(gtkSourceSnippetContext, Str.toStringz(key), Str.toStringz(value)); 150 } 151 152 /** */ 153 public void setLinePrefix(string linePrefix) 154 { 155 gtk_source_snippet_context_set_line_prefix(gtkSourceSnippetContext, Str.toStringz(linePrefix)); 156 } 157 158 /** */ 159 public void setTabWidth(int tabWidth) 160 { 161 gtk_source_snippet_context_set_tab_width(gtkSourceSnippetContext, tabWidth); 162 } 163 164 /** */ 165 public void setUseSpaces(bool useSpaces) 166 { 167 gtk_source_snippet_context_set_use_spaces(gtkSourceSnippetContext, useSpaces); 168 } 169 170 /** 171 * Sets a variable within the context. 172 * 173 * This variable may be overridden by future updates to the 174 * context. 175 * 176 * Params: 177 * key = the variable name 178 * value = the value for the variable 179 */ 180 public void setVariable(string key, string value) 181 { 182 gtk_source_snippet_context_set_variable(gtkSourceSnippetContext, Str.toStringz(key), Str.toStringz(value)); 183 } 184 185 /** 186 * The signal is emitted when a change has been 187 * discovered in one of the chunks of the snippet which has 188 * caused a variable or other dynamic data within the context 189 * to have changed. 190 */ 191 gulong addOnChanged(void delegate(SnippetContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 192 { 193 return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 194 } 195 }